package com.example.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.entity.UserMessage;
import com.example.mapper.UserMessageMapper;
import com.example.service.UsermessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
public class UserMessageServiceImpl extends ServiceImpl<UserMessageMapper, UserMessage> implements UsermessageService {
    @Autowired
    private UserMessageMapper userMessageMapper;

    @Autowired
    private UsermessageService usermessageService;


    public List<UserMessage> selectList(UserMessage userMessage) {
        List<UserMessage> list = userMessageMapper.selectList(new QueryWrapper<UserMessage>().like("openid", userMessage.getOpenid()));
        return list;
    }

    @Override
    public UserMessage getUserMsg(String openid) {
        LambdaQueryWrapper<UserMessage> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(UserMessage::getOpenid, openid);
        if (!StringUtils.isEmpty(openid)) {
            return usermessageService.getOne(queryWrapper);
        }

        return new UserMessage();
    }
}
